package cn.pengpeng.day02.collectionLog;

import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimerTask;

import org.apache.commons.io.FileUtils;

public class CleanTesk extends TimerTask {

	@Override
	public void run() {
		try {
			// 定时清理备份数据
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH");
			Date now = new Date();
			File file = new File("D:/backDir");
			File[] listFiles = file.listFiles();

			for (File dir : listFiles) {
				String hourName = dir.getName();

				Date parse = sdf.parse(hourName);
				if (now.getTime() - parse.getTime() > 24 * 60 * 60 * 24) {
					FileUtils.deleteDirectory(dir);
				}

			}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}
